package com.open.jack.iot3_plugins

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.EncryptUtils
import com.blankj.utilcode.util.StringUtils
import com.open.jack.jk_mpchart.JkChart
import com.open.jack.jk_mpchart.JkLineChart
import com.open.jack.jk_mpchart.listener.IBarChartListener
import com.open.jack.jk_mpchart.model.JkChartType


//https://developer.huawei.com/repo/com/huawei/hms/scanplus/2.1.0.300/scanplus-2.1.0.300.aar
class MainActivity : AppCompatActivity() {
    lateinit var lineView: JkLineChart

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        val lineView1 = findViewById<JkChart>(R.id.lineView1)
        //lineView1.initChart()
        lineView1.setType(JkChartType.LINE)
        lineView1.addLineDataList(1, listOf(20f,14f,50f,60f))
        lineView1.setLineColor(1,"#2EE7B1")

        lineView1.setLeftAxisTextColor("#2EE7B1")
        lineView1.setXAxisTextColor("#2EE7B1")

        lineView1.setXAxisLabel(0,"hehe")
        lineView1.setXAxisLabel(6,"he2he")
        lineView1.updateView()


        val barView = findViewById<JkChart>(R.id.barView1)
        //barView.initChart()
        barView.setType(JkChartType.BAR)
        barView.addBarDataList(listOf(12f,1f,5f,6f,1f,1f,2f))
        // val labels = arrayOf("0~0.002", "0.002~0.04", "0.04~0.12", "0.12以上", "离线")
        barView.setXAxisLabel(0,"0~0.002")
        barView.setXAxisLabel(1,"0.002~0.04")
        barView.setXAxisLabel(2,"0.04~0.12")
        barView.setXAxisLabel(3,"0.12以上")
        barView.setXAxisLabel(4,"离线")
        barView.setXAxisLabel(5,"离线")
        barView.setXAxisLabel(6,"离线")
        barView.setXAxisLabel(7,"离线")
        barView.setXAxisLabel(8,"离线")

//
        //barView.setBarColor("#2EE7B1")
        barView.setXAxisLabel(9,"he2he")


        barView.setMinOffset(10f)
        barView.setXAxisTextSize(20f)

//
        barView.setLeftAxisTextColor("#2EE7B1")
        barView.setXAxisTextColor("#2EE7B1")


        barView.setLeftAxiGridColor("#2EE7B1")
        barView.setBarChartListener(object : IBarChartListener {
            override fun onItemSelected(index: Int,value:Float) {
                Log.d("TAG", "onItemSelected: "+index+" "+value)
            }
        })

        barView.updateView()
        findViewById<View>(R.id.button1).setOnClickListener {
            barView?.clearHighlight()
        }

//        barView.setOnChartValueSelectedListener(object :OnChartValueSelectedListener{
//            override fun onValueSelected(e: Entry?, h: Highlight?) {
//                Log.d("TAG", "onValueSelected: ")
//            }
//
//            override fun onNothingSelected() {
//                Log.d("TAG", "onNothingSelected: ")
//            }
//
//        })

    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
}

